'''
@author: harumonia
@site:
@datetime: 2020/3/14 20:37
@software: PyCharm
'''
from flask_admin import AdminIndexView, expose

from application.extensions import db
from application.utils.time_handler import get_now_datetime


class Basedb(db.Model):
    __abstract__ = True

    # author_id = db.Column(db.BigInteger, db.ForeignKey('user.id'))

    def init(self, data):
        '''
        初始化函数
        :param data: Dict , 存储的是与数据库直接关联的
        :return:
        '''
        data['create_date'] = get_now_datetime()
        data['status'] = True

        for k, v in data.items():
            if hasattr(self, k) and k != 'id':
                setattr(self, k, v)
        db.session.add(self)
        db.session.commit()


